<template>
  <div id="list">
  	<ul style="padding-left: 0px;">
  		<li v-for="item in users"
			:class="{ active: currentSession ? item.name === currentSession.name : false }"
			v-on:click="changeCurrentSession(item)"
			v-if="filterKey.trim()==='' || item.name.indexOf(filterKey.trim())!==-1">
			<el-badge :value="usersRead[currentUser.username+'#'+item.username]" :max="99" class="item" :hidden="usersRead[currentUser.username+'#'+item.username]===0">
			<img class="avatar" :src="item.avatar" :alt="item.name">
			</el-badge>
			<p class="name">{{item.name}}</p>
  		</li>
  	</ul>
  </div>
</template>

<script>
import {mapState} from 'vuex'

export default {
  name: 'list',
  data () {
    return {

    }
  },
  computed: mapState([
  		'currentUser',
  		'users',
  		'currentSession',
	  	'usersRead',
	  	'filterKey'
	]),
  methods:{
  	changeCurrentSession:function (item) {
  		this.$store.commit('changeCurrentSession',item)
  	}
  }
}
</script>
<style scoped>
	.item {
		margin-top: 10px;

	}
</style>
<style lang="scss" scoped>

#list {
	li {
		padding: 0px 15px;
		border-bottom: 1px solid #292C33;
		cursor: pointer;
		list-style: none;
		&:hover {
			background-color: rgba(255, 255, 255, 0.03);
		}
	}
  li.active {/*注意这个是.不是冒号:*/
			background-color: rgba(255, 255, 255, 0.1);
	}
	.avatar {
		border-radius: 2px;
		width: 30px;
		height: 30px;
		vertical-align: middle;
	}
	.name {
		display: inline-block;
		margin-left: 15px;
	}
}
</style>
